import pymysql

#cursorclass=pymysql.cursors.DictCursor 修改为字典型游标
def main():
    conn = pymysql.connect(host="182.247.245.27",port=10190,user='root',password='dyk19891019',db='school',charset='utf8',
                           cursorclass=pymysql.cursors.DictCursor)

    try:
        with conn.cursor() as cureor:
            cureor.execute('select stuname,stuaddr from tb_student')
            #默认拿到的是元组游标
            # for row in cureor.fetchall():
            #     print(f'姓名: {row[0]}')
            #     print(f'地址: {row[1]}')
            #     print('-'*20)


        for row in cureor.fetchall():
            print(row['stuname'],end='\t')
            print(row['stuaddr'])

    except pymysql.MySQLError as error:
        print(error)
    finally:
        conn.close()





if __name__ == '__main__':
    main()